﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DcsGauges.Gui.Gauges.Interfaces;
using DcsGauges.Gui.Gauges.Panels;
using DcsGauges.DataStructures;
using DcsGauges.Shared.Exceptions;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace DcsGauges.Gui.Views.Concrete
{
    class ElectricalAndOxygenRegulatorView : View, IMultiTriggerGauge
    {
        #region Fields & Properties

        private ElectricalPanel                         elecPanel                       = null;
        private OxygenPanel                             oxygenPanel                     = null;

        #endregion


        #region Constructors

        public ElectricalAndOxygenRegulatorView()
        {
            this.elecPanel                  = new ElectricalPanel(this, new URect(new ULoc(0.0f, 0.0f),  new USize(1.0f, 0.6f)));
            this.oxygenPanel                = new OxygenPanel(this,     new URect(new ULoc(0.0f, 0.6f),  new USize(1.0f, 0.4f)));
        }

        #endregion


        #region Interface Implementation

        #region Events

        public event EventHandler<TriggerValueEventArgs>  TriggerEvent                  = delegate { };

        #endregion

        #region Properties
        
        public Shared.DataStructures.DcsProperty[] Properties
        {
            get { return this.elecPanel.Properties.Concat(this.oxygenPanel.Properties).ToArray(); }
        }

        public void SetValue(Shared.DataStructures.DcsProperty property, float value)
        {
            if (this.elecPanel.Properties.Contains(property))
            {
                this.elecPanel.SetValue(property, value);
            }
            else if (this.oxygenPanel.Properties.Contains(property))
            {
                this.oxygenPanel.SetValue(property, value);
            }
            else
            {
                throw new DcsArgumentException(string.Format(Localization.ExcPropertyInvalidForGauge2A, property.Name, typeof(ElectricalAndOxygenRegulatorView)));
            }
        }

        public float GetValue(Shared.DataStructures.DcsProperty property)
        {
            if (this.elecPanel.Properties.Contains(property))
            {
                float value = this.elecPanel.GetValue(property);
                return value;
            }
            else if (this.oxygenPanel.Properties.Contains(property))
            {
                float value = this.oxygenPanel.GetValue(property);
                return value;
            }
            else
            {
                throw new DcsArgumentException(string.Format(Localization.ExcPropertyInvalidForGauge2A, property.Name, typeof(ElectricalAndOxygenRegulatorView)));
            }
        }

        #endregion

        #endregion


        #region Overrides

        public override void Render(SpriteBatch spriteBatch, GraphicsDevice device, Rectangle parentRect, float globalZIndex)
        {
            this.elecPanel.Render(spriteBatch, device, parentRect, globalZIndex);
            this.oxygenPanel.Render(spriteBatch, device, parentRect, globalZIndex);
        }

        #endregion
    }
}
